package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.bean.LunTaiBeen;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/15   11:20
 * Description:HuanluntaiAdapter
 */

public class HuanluntaiAdapter extends BaseAdapter {

    private Context context;
    private List<LunTaiBeen> datas;

    public HuanluntaiAdapter(Context context, List<LunTaiBeen> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas != null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.luntai_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.content.setText(datas.get(position).getName());
        holder.price.setText("价格："+datas.get(position).getPrice());
        holder.assess.setText("评价："+datas.get(position).getAssess());
        holder.xiaoliang.setText("销量："+datas.get(position).getXiaoliang());
        return convertView;
    }

    /**
     * private String name;
     private int price;
     private int assess;
     private int xiaoliang;
     */
    static class ViewHolder{
        private TextView content,price,assess,xiaoliang;
        public ViewHolder(View view) {

            content = (TextView) view.findViewById(R.id.luntai_content);
            price = (TextView) view.findViewById(R.id.price_luntai_item);
            assess = (TextView) view.findViewById(R.id.assess_luntai_item);
            xiaoliang = (TextView) view.findViewById(R.id.xiaoliang_luntai_item);
        }
    }
}
